/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

package edu.gatech.jiggawatt.office.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import edu.gatech.jiggawatt.office.model.Appointment;
import edu.gatech.jiggawatt.office.model.DailySchedule;
import edu.gatech.jiggawatt.office.model.Doctor;
import edu.gatech.jiggawatt.office.model.MonthlySchedule;
import edu.gatech.jiggawatt.office.model.Patient;
import edu.gatech.jiggawatt.office.model.TreatmentRecord;
import edu.gatech.jiggawatt.office.model.YearlySchedule;
import edu.gatech.jiggawatt.office.model.Time;
import edu.gatech.jiggawatt.office.presenter.Presenter;
import java.awt.Font;

/**
 * Represents Patient Frame
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0
 *
 */
public class PatientFrame extends JFrame { // $codepro.audit.disable declareDefaultConstructors

	private Presenter presenter;
	private JPanel contentPane;
	private DefaultComboBoxModel doctorModel;
	private DefaultComboBoxModel yearModel;
	private DefaultComboBoxModel monthModel;
	private DefaultComboBoxModel dayModel;
	private DefaultComboBoxModel timeModel;
	private JComboBox comboBox_month;
	private JComboBox comboBox_day;
	private JComboBox comboBox_time;
	private JComboBox comboBox_year;
	private JComboBox comboBox_desiredDoctor;
	private JTextArea reasonArea;
	private DefaultListModel appointmentModel;
	private DefaultListModel trModel;
	private JList list_scheduledAppointments;
	private JList trList;
	private JTextArea chiefComplaintArea;
	private JTextArea diagnosisArea;
	
	private int year;	
	private int month;
	private int day;
	private int hour;
	private int minute;
	
	private String userId;
	private JTextField treatingDoctorField;
	private JTextField dateField;
	private JTextField timeField;
	private JTextField attendingNurseField;
	private JTextField bloodPressureField;
	private JTextField pulseField;
	private JTextField temperatureField;
	private JTextField heightField;
	private JTextField weightField;
	
	private JButton btnViewDoctorsOrder;
	private JButton btnViewInvoice;
	
	
	/**
	 * Create the frame.
	 * @param p presenter
	 * @param id id of patient
	 */
	public PatientFrame(Presenter p, String id) {
		userId = id;
		presenter = p;
		setTitle("Awesome Office"); // $codepro.audit.disable stringLiterals
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600); // $codepro.audit.disable numericLiterals
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); // $codepro.audit.disable numericLiterals
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		Calendar calendar = Calendar.getInstance();
		year = calendar.get(Calendar.YEAR);
		month = calendar.get(Calendar.MONTH) + 1;		
		day = calendar.get(Calendar.DAY_OF_MONTH);
		hour = calendar.get(Calendar.HOUR_OF_DAY);
		minute = calendar.get(Calendar.MINUTE);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 60, 774, 493); // $codepro.audit.disable numericLiterals
		contentPane.add(panel);
		panel.setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(0, 0, 774, 493); // $codepro.audit.disable numericLiterals
		panel.add(tabbedPane);
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("Appointment", null, panel_2, null); // $codepro.audit.disable stringLiterals
		panel_2.setLayout(null);
		
		JLabel lblDesiredDoctor = new JLabel("Desired Doctor:"); // $codepro.audit.disable stringLiterals
		lblDesiredDoctor.setBounds(20, 57, 112, 14); // $codepro.audit.disable numericLiterals
		panel_2.add(lblDesiredDoctor);
		
		JLabel lblDate = new JLabel("Date (YYYY/MM/DD):"); // $codepro.audit.disable stringLiterals
		lblDate.setBounds(20, 93, 128, 14); // $codepro.audit.disable numericLiterals
		panel_2.add(lblDate);
		
		comboBox_month = new JComboBox();
		comboBox_month.setEnabled(false);
		comboBox_month.setBounds(227, 90, 46, 20); // $codepro.audit.disable numericLiterals
		panel_2.add(comboBox_month);
		
		comboBox_day = new JComboBox();
		comboBox_day.setEnabled(false);
		comboBox_day.setBounds(283, 90, 46, 20); // $codepro.audit.disable numericLiterals
		panel_2.add(comboBox_day);
		
		JLabel lblTime = new JLabel("Time:"); // $codepro.audit.disable stringLiterals
		lblTime.setBounds(20, 130, 88, 14); // $codepro.audit.disable numericLiterals
		panel_2.add(lblTime);
		
		JLabel lblReason = new JLabel("Reason:"); // $codepro.audit.disable stringLiterals
		lblReason.setBounds(20, 166, 62, 14); // $codepro.audit.disable numericLiterals
		panel_2.add(lblReason);
		
		reasonArea = new JTextArea();
		reasonArea.setBounds(20, 193, 339, 204); // $codepro.audit.disable numericLiterals
		panel_2.add(reasonArea);
		
		JButton btnRequest = new JButton("Request"); // $codepro.audit.disable stringLiterals
		btnRequest.setBounds(126, 420, 135, 23);
		panel_2.add(btnRequest);
		
		JPanel panel_scheduledAppointments = new JPanel();
		panel_scheduledAppointments.setBounds(422, 69, 318, 343);
		panel_2.add(panel_scheduledAppointments);
		panel_scheduledAppointments.setLayout(null);
		
		JScrollPane scrollPane_scheduledAppointments = new JScrollPane();
		scrollPane_scheduledAppointments.setBounds(10, 11, 298, 317);
		panel_scheduledAppointments.add(scrollPane_scheduledAppointments);
		
		JButton btnCancelAppointment = new JButton("Remove"); // $codepro.audit.disable stringLiterals
		btnCancelAppointment.setBounds(596, 420, 135, 23);
		panel_2.add(btnCancelAppointment);
		
		JLabel lblCurrentAppointments = new JLabel("Current Appointments:"); // $codepro.audit.disable stringLiterals
		lblCurrentAppointments.setBounds(432, 44, 142, 14);
		panel_2.add(lblCurrentAppointments);
		
		comboBox_time = new JComboBox();
		comboBox_time.setEnabled(false);
		comboBox_time.setBounds(148, 127, 125, 20);
		panel_2.add(comboBox_time);
		
		yearModel = new DefaultComboBoxModel();
		for (YearlySchedule e : presenter.getYearlySchedules())
		{
			if (e.getYear() >= year)
			{
				yearModel.addElement(e);
			}
		}
		
		monthModel = new DefaultComboBoxModel();
		dayModel = new DefaultComboBoxModel();
		timeModel = new DefaultComboBoxModel();
		
		comboBox_year = new JComboBox(yearModel);
		comboBox_year.setSelectedIndex(-1);
		comboBox_year.setBounds(148, 90, 69, 20);
		panel_2.add(comboBox_year);
		
		comboBox_year.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				JComboBox yearBox = (JComboBox) e.getSource();
				YearlySchedule selectedYear = (YearlySchedule) yearBox.getSelectedItem();
				
				monthModel.removeAllElements();
				dayModel.removeAllElements();
				for (MonthlySchedule m : selectedYear.getMonthlySchedules())
				{
					if (m.getMonth() >= month || selectedYear.getYear() != year)
					{
						monthModel.addElement(m);
					}
				}
				comboBox_month.setModel(monthModel);
				comboBox_month.setSelectedIndex(-1);
				comboBox_month.setEnabled(true);
				comboBox_day.setSelectedIndex(-1);
				comboBox_day.setEnabled(false);
				comboBox_time.setSelectedIndex(-1);
				comboBox_time.setEnabled(false);
			}
		});
		
		comboBox_month.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				if (comboBox_month.getSelectedIndex() != -1)
				{

					JComboBox monthBox = (JComboBox) e.getSource();
					MonthlySchedule selectedMonth = (MonthlySchedule) monthBox.getSelectedItem();
				
					dayModel.removeAllElements();
					for (DailySchedule d : selectedMonth.getDailySchedules())
					{
						if (d.getDay() >= day || (selectedMonth.getMonth() != month || selectedMonth.getYear() != year))
						{
							dayModel.addElement(d);
						}
					}
					comboBox_day.setModel(dayModel);
					comboBox_day.setSelectedIndex(-1);
					comboBox_day.setEnabled(true);
					comboBox_time.setSelectedIndex(-1);
					comboBox_time.setEnabled(false);
				}
			}
		});
		
		comboBox_day.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				if (comboBox_day.getSelectedIndex() != -1)
				{
					JComboBox dayBox = (JComboBox) e.getSource();
					DailySchedule selectedDay = (DailySchedule) dayBox.getSelectedItem();
				
					timeModel.removeAllElements();
					Appointment[] appointments = selectedDay.getAppointments();
					
					for (int i = 0; i < appointments.length; i++)
					{
						int timeHour = (i * 30 + 540) / 60; // $codepro.audit.disable variableDeclaredInLoop
						int timeMinute = (i * 30 + 540) % 60; // $codepro.audit.disable variableDeclaredInLoop

						if (null == appointments[i] && (selectedDay.getDay() != day || selectedDay.getMonth() != month || selectedDay.getYear() != year
								|| timeHour > hour || (timeHour == hour && timeMinute > minute )))
						{
							timeModel.addElement(new Time(timeHour, timeMinute));
						}
						comboBox_time.setModel(timeModel);
						comboBox_time.setSelectedIndex(-1);
						comboBox_time.setEnabled(true);
					}
				}
			}
		});		
		
		doctorModel = new DefaultComboBoxModel();
		for (Doctor e : presenter.getDoctorList())
		{
			doctorModel.addElement(e);
		}
		
		comboBox_desiredDoctor = new JComboBox(doctorModel);
		comboBox_desiredDoctor.setBounds(148, 54, 181, 20);
		panel_2.add(comboBox_desiredDoctor);
		
		JLabel lblToday = new JLabel("Today is: " + getDate()); // $codepro.audit.disable stringLiterals
		lblToday.setBounds(20, 11, 142, 14);
		panel_2.add(lblToday);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("History", null, panel_1, null); // $codepro.audit.disable stringLiterals
		panel_1.setLayout(null);
		
		JLabel lblTreatmentRecords = new JLabel("Treatment Records:"); // $codepro.audit.disable stringLiterals
		lblTreatmentRecords.setBounds(10, 11, 117, 14);
		panel_1.add(lblTreatmentRecords);
		
		btnViewInvoice = new JButton("View Invoice"); // $codepro.audit.disable stringLiterals
		btnViewInvoice.setEnabled(false);
		btnViewInvoice.setBounds(548, 431, 170, 23);
		panel_1.add(btnViewInvoice);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 32, 213, 388);
		panel_1.add(scrollPane);
		
		trModel = new DefaultListModel();
		
		for (TreatmentRecord tr : presenter.getTreatmentRecords(userId))
		{
			trModel.addElement(tr);
		}
		
		trList = new JList(trModel);
		scrollPane.setViewportView(trList);
		
		JLabel lblRecordDetails = new JLabel("Record Details:"); // $codepro.audit.disable stringLiterals
		lblRecordDetails.setBounds(240, 11, 152, 14);
		panel_1.add(lblRecordDetails);
		
		JLabel lblTreatingDoctor = new JLabel("Treating Doctor:"); // $codepro.audit.disable stringLiterals
		lblTreatingDoctor.setBounds(240, 47, 95, 14);
		panel_1.add(lblTreatingDoctor);
		
		treatingDoctorField = new JTextField();
		treatingDoctorField.setFont(new Font("Tahoma", Font.BOLD, 11)); // $codepro.audit.disable stringLiterals
		treatingDoctorField.setEnabled(false);
		treatingDoctorField.setEditable(false);
		treatingDoctorField.setBounds(345, 44, 117, 20);
		panel_1.add(treatingDoctorField);
		treatingDoctorField.setColumns(10);
		
		JLabel lblDate_1 = new JLabel("Date:"); // $codepro.audit.disable stringLiterals
		lblDate_1.setBounds(240, 78, 46, 14);
		panel_1.add(lblDate_1);
		
		dateField = new JTextField();
		dateField.setFont(new Font("Tahoma", Font.BOLD, 11)); // $codepro.audit.disable stringLiterals
		dateField.setEnabled(false);
		dateField.setEditable(false);
		dateField.setBounds(345, 75, 117, 20);
		panel_1.add(dateField);
		dateField.setColumns(10);
		
		btnViewDoctorsOrder = new JButton("View Doctor's Order"); // $codepro.audit.disable stringLiterals
		btnViewDoctorsOrder.setEnabled(false);
		btnViewDoctorsOrder.setBounds(345, 431, 170, 23);
		panel_1.add(btnViewDoctorsOrder);
		
		JLabel lblTime_1 = new JLabel("Time:"); // $codepro.audit.disable stringLiterals
		lblTime_1.setBounds(240, 120, 46, 14);
		panel_1.add(lblTime_1);
		
		JLabel lblAttendingNurse = new JLabel("Attending Nurse:"); // $codepro.audit.disable stringLiterals
		lblAttendingNurse.setBounds(240, 145, 95, 14);
		panel_1.add(lblAttendingNurse);
		
		timeField = new JTextField();
		timeField.setFont(new Font("Tahoma", Font.BOLD, 11)); // $codepro.audit.disable stringLiterals
		timeField.setEnabled(false);
		timeField.setEditable(false);
		timeField.setBounds(345, 109, 117, 20);
		panel_1.add(timeField);
		timeField.setColumns(10);
		
		attendingNurseField = new JTextField();
		attendingNurseField.setFont(new Font("Tahoma", Font.BOLD, 11)); // $codepro.audit.disable stringLiterals
		attendingNurseField.setEnabled(false);
		attendingNurseField.setEditable(false);
		attendingNurseField.setBounds(345, 142, 117, 20);
		panel_1.add(attendingNurseField);
		attendingNurseField.setColumns(10);
		
		JLabel lblCheifComplaint = new JLabel("Cheif Complaint:"); // $codepro.audit.disable stringLiterals
		lblCheifComplaint.setBounds(240, 189, 95, 14);
		panel_1.add(lblCheifComplaint);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(345, 183, 117, 108);
		panel_1.add(scrollPane_1);
		
		chiefComplaintArea = new JTextArea();
		chiefComplaintArea.setFont(new Font("Monospaced", Font.BOLD, 13)); // $codepro.audit.disable stringLiterals
		chiefComplaintArea.setEnabled(false);
		chiefComplaintArea.setEditable(false);
		scrollPane_1.setViewportView(chiefComplaintArea);
		
		JLabel lblBloodPressure = new JLabel("Blood Pressure:"); // $codepro.audit.disable stringLiterals
		lblBloodPressure.setBounds(495, 47, 102, 14);
		panel_1.add(lblBloodPressure);
		
		bloodPressureField = new JTextField();
		bloodPressureField.setFont(new Font("Tahoma", Font.BOLD, 11)); // $codepro.audit.disable stringLiterals
		bloodPressureField.setEnabled(false);
		bloodPressureField.setEditable(false);
		bloodPressureField.setBounds(607, 44, 136, 20);
		panel_1.add(bloodPressureField);
		bloodPressureField.setColumns(10);
		
		JLabel lblPulse = new JLabel("Pulse:");
		lblPulse.setBounds(495, 78, 46, 14);
		panel_1.add(lblPulse);
		
		pulseField = new JTextField();
		pulseField.setFont(new Font("Tahoma", Font.BOLD, 11));
		pulseField.setEnabled(false);
		pulseField.setEditable(false);
		pulseField.setBounds(607, 75, 136, 20);
		panel_1.add(pulseField);
		pulseField.setColumns(10);
		
		JLabel lblTemperature = new JLabel("Temperature:");
		lblTemperature.setBounds(495, 109, 66, 14);
		panel_1.add(lblTemperature);
		
		temperatureField = new JTextField();
		temperatureField.setFont(new Font("Tahoma", Font.BOLD, 11));
		temperatureField.setEnabled(false);
		temperatureField.setEditable(false);
		temperatureField.setBounds(607, 106, 136, 20);
		panel_1.add(temperatureField);
		temperatureField.setColumns(10);
		
		JLabel lblHeight = new JLabel("Height:");
		lblHeight.setBounds(495, 145, 46, 14);
		panel_1.add(lblHeight);
		
		JLabel lblWeight = new JLabel("Weight:");
		lblWeight.setBounds(495, 180, 46, 14);
		panel_1.add(lblWeight);
		
		heightField = new JTextField();
		heightField.setFont(new Font("Tahoma", Font.BOLD, 11));
		heightField.setEnabled(false);
		heightField.setEditable(false);
		heightField.setBounds(607, 142, 136, 20);
		panel_1.add(heightField);
		heightField.setColumns(10);
		
		weightField = new JTextField();
		weightField.setFont(new Font("Tahoma", Font.BOLD, 11));
		weightField.setEnabled(false);
		weightField.setEditable(false);
		weightField.setBounds(607, 177, 136, 20);
		panel_1.add(weightField);
		weightField.setColumns(10);
		
		JLabel lblDiagnosis = new JLabel("Diagnosis:");
		lblDiagnosis.setBounds(495, 218, 66, 14);
		panel_1.add(lblDiagnosis);
		
		JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(607, 218, 136, 120);
		panel_1.add(scrollPane_2);
		
		diagnosisArea = new JTextArea();
		diagnosisArea.setFont(new Font("Monospaced", Font.BOLD, 13));
		diagnosisArea.setEditable(false);
		diagnosisArea.setEnabled(false);
		scrollPane_2.setViewportView(diagnosisArea);
		
		JLabel lblPatientLoggedIn = new JLabel("Patient logged in as : " + id);
		lblPatientLoggedIn.setBounds(10, 11, 300, 25);
		contentPane.add(lblPatientLoggedIn);
		
		JButton btnLogout = new JButton("Logout");
		btnLogout.setBounds(193, 12, 89, 23);
		contentPane.add(btnLogout);
		
		appointmentModel = new DefaultListModel();
		
		for (Appointment app : ((Patient) presenter.getUser(id)).getAppointments())
		{
			appointmentModel.addElement(app);
		}
		
		list_scheduledAppointments = new JList(appointmentModel);
		scrollPane_scheduledAppointments.setViewportView(list_scheduledAppointments);
		
		JButton btnViewEditAppointment = new JButton("View/Edit");
		btnViewEditAppointment.setBounds(432, 420, 154, 23);
		panel_2.add(btnViewEditAppointment);
		
		btnRequest.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				if (comboBox_year.getSelectedIndex() == -1 || comboBox_month.getSelectedIndex() == -1
						|| comboBox_day.getSelectedIndex() == -1 || comboBox_time.getSelectedIndex() == -1 
						|| reasonArea.getText().equals(""))
				{
					JOptionPane.showMessageDialog(null, "You must fill all items", 
							"Error", JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					int year = ((YearlySchedule) comboBox_year.getSelectedItem()).getYear();
					int month = ((MonthlySchedule) comboBox_month.getSelectedItem()).getMonth();
					int day = ((DailySchedule) comboBox_day.getSelectedItem()).getDay();
					Time time = ((Time) comboBox_time.getSelectedItem());
					String desiredDoctor = ((Doctor) comboBox_desiredDoctor.getSelectedItem()).getFullName();
					String reason = reasonArea.getText();
					
					Appointment newAppointment = new Appointment(userId, new edu.gatech.jiggawatt.office.model.Date(year,month,day), time, desiredDoctor, reason);
					presenter.addAppointment(newAppointment);
					
					comboBox_month.setSelectedIndex(-1);
					comboBox_month.setEnabled(true);
					comboBox_day.setSelectedIndex(-1);
					comboBox_day.setEnabled(false);
					comboBox_time.setSelectedIndex(-1);
					comboBox_time.setEnabled(false);
					reasonArea.setText("");
					
					appointmentModel.clear();

					for (Appointment app : ((Patient) presenter.getUser(userId)).getAppointments())
					{
						appointmentModel.addElement(app);
					}
				}
			}
		});
		
		btnCancelAppointment.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				if (list_scheduledAppointments.getSelectedIndex() == -1)
				{
					JOptionPane.showMessageDialog(null, "You must select an appointment to remove", 
							"Error", JOptionPane.ERROR_MESSAGE);					
				}
				else
				{
					Appointment selectedApp = (Appointment) list_scheduledAppointments.getSelectedValue();
					presenter.removeAppointment(selectedApp.getDate(), selectedApp.getTime());
					
					appointmentModel.clear();

					for (Appointment app : ((Patient) presenter.getUser(userId)).getAppointments())
					{
						appointmentModel.addElement(app);
					}
				}				
			}
		});
		
		btnViewEditAppointment.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				if (list_scheduledAppointments.getSelectedIndex() == -1)
				{
					JOptionPane.showMessageDialog(null, "You must select an appointment to view", 
							"Error", JOptionPane.ERROR_MESSAGE);					
				}
				else
				{
					JFrame viewEditAppointmentFrame = new ViewEditAppointmentFrame(presenter, 
							(Appointment) list_scheduledAppointments.getSelectedValue(), appointmentModel);
					viewEditAppointmentFrame.setVisible(true);
				}		
			}
		});
		
		trList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent e) 
			{
				if (trList.getSelectedIndex() == -1)
				{
					treatingDoctorField.setText("");
					dateField.setText("");
					timeField.setText("");
					attendingNurseField.setText("");
					chiefComplaintArea.setText("");
					bloodPressureField.setText("");
					pulseField.setText("");
					temperatureField.setText("");
					heightField.setText("");
					weightField.setText("");
					diagnosisArea.setText("");
					btnViewInvoice.setEnabled(false);
					btnViewDoctorsOrder.setEnabled(false);
				}
				else
				{
					TreatmentRecord tr = (TreatmentRecord) trList.getSelectedValue();
					treatingDoctorField.setText(tr.getTreatingDoctor());
					dateField.setText(tr.getDate().toString());
					timeField.setText(tr.getTime().toString());
					attendingNurseField.setText(tr.getAttendingNurse());
					chiefComplaintArea.setText(tr.getChiefComplaint());
					bloodPressureField.setText(tr.getBloodPressure()+"");
					pulseField.setText(tr.getPulse()+"");
					temperatureField.setText(tr.getTemperature()+"");
					heightField.setText(tr.getHeight()+"");
					weightField.setText(tr.getWeight()+"");
					diagnosisArea.setText(tr.getDiagnosis());
					btnViewInvoice.setEnabled(true);
					btnViewDoctorsOrder.setEnabled(true);
				}
			}
		});
		
		btnViewDoctorsOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				JFrame ViewEditDoctorsOrderFrame = new ViewEditDoctorsOrderFrame(presenter, userId, (TreatmentRecord) trList.getSelectedValue(), false); // $codepro.audit.disable localVariableNamingConvention
				ViewEditDoctorsOrderFrame.setVisible(true);
			}
		});
		
		btnViewInvoice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JFrame ViewInvoiceFrame = new ViewInvoiceFrame(presenter, userId, (TreatmentRecord) trList.getSelectedValue()); // $codepro.audit.disable localVariableNamingConvention
				ViewInvoiceFrame.setVisible(true);
			}
		});
	
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				setVisible(false);
				dispose();
				JFrame loginFrame = new LoginFrame(presenter);
				loginFrame.setVisible(true);
			}
		});
	}
	
	/**
	 * returns string format of today's date
	 * @return string format of today's date
	 */
	private String getDate()
	{
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
		Date date = new Date();

		return dateFormat.format(date);
	}
}
